<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>

</body>

<!--反转字符串中的单词--------------------------------------------------------------------------------------------------->
<script type="text/html">
    //
    func = (str) => {
    let strArr = str.split(" ");
    let res = strArr.map(item => {
    return item.split('').reverse().join('');
    });
    return res.join(' ');
    };
    console.log(func("let's take LeetCode contest"));
</script>

<!--寻找二进制字串------------------------------------------------------------------------------------------------------>
<script type="text/html">
    //
    func = (str) => {
    let arr = str.split(''), length = arr.length, res = [];
    for (let i = 0; i < length - 1; i++) {
    let x = [arr[i]];
    for (let j = i + 1; j < length; j++)
    if (arr[j] === arr[i])
    x.push(arr[j]);
    else {
    let l = x.length, is = true;
    for (let k = 0; k < l; k++)
    if (!arr[k + j] || arr[k + j] === arr[i]) {
    is = false;
    break;
    } else
    x.push(arr[k + j]);
    if (is)
    res.push(x.join(''));
    break;
    }
    }
    return res;
    };
    console.log(func("00110011"));
    console.log(func("00110011001"));
    console.log(func('10101'));
</script>

<!--卡牌分组----------------------------------------------------------------------------------------------------------->
<script type="text/html">
    //
    func = (a) => {
    if (a.length < 2)
    return false;
    let str = a.sort().join('');
    console.log(str);
    let arr = str.match(/(\d)\1*/g).sort((a, b) => {
    return a.length > b.length;
    });
    console.log(arr);
    let l = arr[0].length, length = arr.length;
    if (l === 1)
    return false;
    for (let i = 0; i < length; i++)
    if (arr[i].length % l !== 0)
    return false;
    return true;
    };
    console.log(func([1, 1, 1, 2, 2, 2, 3, 3]));
    console.log(func([1, 1, 1, 2, 2, 2, 3, 3, 3]));
    console.log(func([1, 1, 2, 2, 2, 2]));
    console.log(func([1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 1, 1, 3, 3, 3, 3]));
</script>

<!--种花问题----------------------------------------------------------------------------------------------------------->
<script type="text/html">
    //
    func=(flowerbed,n)=>{
    if(flowerbed&&flowerbed===[0])
    return n<=1;
    let str=flowerbed.join('');
    let ends=str.match(/^(00)+|(00)+$/g);
    let arr=str.match(/0{3,}/g),ret=0;
    if(arr)
    for(let i=0;i< arr.length;i++)
    ret+=Math.floor((arr[i].length-1)/2);
    return ret+(ends?ends.length:0)>=n;
    };
    console.log(func('00000'.split(''),2));
</script>

<!--种花问题第二种方法--------------------------------------------------------------------------------------------------->
<script>
    // type="text/html"
    func = (flowerbed, n) => {
        flowerbed.unshift(0);
        let num = 0;
        for (let i = 0, len = flowerbed.length; i < len; i++)
            if (flowerbed[i] === 0) {
                if (flowerbed[i - 1] === 0 && !flowerbed[i + 1]) {
                    num++;
                    i++;
                }
            }
        return num >= n;
    };
    console.log(func('00000'.split(''), 2));
</script>

</html>